package susebs.pb.travel_server.controller;

import org.springframework.web.bind.annotation.*;
import susebs.pb.travel_server.domain.PageDto;
import susebs.pb.travel_server.domain.Result;
import susebs.pb.travel_server.entity.Hotels;
import susebs.pb.travel_server.service.HotelsService;
import susebs.pb.travel_server.service.LandmarksService;
import susebs.pb.travel_server.service.NavigationsService;

import javax.annotation.Resource;
import java.util.ArrayList;
import java.util.List;

/**
 * 景区控制层
 */
@RestController
@RequestMapping("/landmarks")
@CrossOrigin
public class LandmarksController {
    @Resource
    private LandmarksService landmarksService;
    @Resource
    private HotelsService hotelsService;
    @Resource
    private NavigationsService navigationsService;

    /**
     * 分页查询
     * @param pageDto 景点实体+分页数据
     * @return 包含图片的景点列表
     */
    @PostMapping("/queryByPage")
    public Result queryByPage(@RequestBody PageDto pageDto){
        List list = landmarksService.queryAllLmsByPage(pageDto).getList();
        if(list.isEmpty())return Result.buildFail("未查到相关信息！");
        ArrayList res = navigationsService.getListsAndPics(list);
        return Result.buildSuccess(res);
    }

    /**
     * 景区附近酒店
     * @param pageDto 景点实体+分页数据
     * @return 包含图片的酒店列表
     */
    @PostMapping("/landmarksNearby")
    public Result landmarksNearby(@RequestBody PageDto pageDto){
        String landmarkCity = pageDto.getLandmarks().getCity();

        //设置请求参数
        Hotels params = new Hotels();
        params.setCity(landmarkCity);
        pageDto.setHotels(params);

        //发起请求
        List list = hotelsService.queryAllHotelsByPage(pageDto).getList();
        ArrayList res = navigationsService.getListsAndPics(list);

        return Result.buildSuccess(res);

    }

    //管理
    //删
    @GetMapping("/deleteById")
    public Result deleteById(Long lmId){
        boolean delete = landmarksService.deleteById(lmId);
        if(delete)return Result.buildSuccess();
        return Result.buildFail("删除失败！");
    }

}
